using System.Linq;
using System.Reflection;

namespace TestMonkey.Models
{
	/// <summary>
	/// This repesents a constructor.
	/// </summary>
	public class ConstructorModel
	{
		readonly ConstructorInfo m_Constructor;

		/// <summary>
		/// Initializes a new instance of the <see cref="ConstructorModel"/> class.
		/// </summary>
		/// <param name="constructor">The constructor.</param>
		public ConstructorModel(ConstructorInfo constructor)
		{
			m_Constructor = constructor;
		}

		/// <summary>
		/// This returns a name that can be used as an identifier.
		/// </summary>
		public CodeString SafeName
		{
			get
			{
				var parameters = m_Constructor.GetParameters();
				if (parameters.Count() == 0)
					return "Default";

				var list = from p in parameters select p.ParameterType.Name.Replace("<", "").Replace(">", "").Replace("`", "");
				return string.Join("_", list);
			}
		}

		/// <summary>
		/// Gets the constructor code.
		/// </summary>
		/// <returns></returns>
		public CodeString GetConstructorCode()
		{
			return m_Constructor.GetConstructorCode();
		}

		/// <summary>
		/// Gets a value indicating whether this instance is creatable using our current code generator.
		/// </summary>
		/// <value>
		/// <c>true</c> if this instance is creatable; otherwise, <c>false</c>.
		/// </value>
		public bool IsCreatable
		{
			get { return m_Constructor.IsCreatable(); }
		}
	}
}
